<?php

namespace app\payment\model;

use app\user\model\User as UserModel;
use think\Model;

/**
 * 商户支付配置模型
 */
class Mconfig extends Model {

    // 设置当前模型对应的完整数据表名称
    protected $name = 'payment_merchant_config';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * 获取应用配置
     * @param  array $name  支付键名
     * @param  array $group 支付分组
     * @return mixed
     */
    public static function getMerchant($name = [], $group = []) {

        $arr = [];
        foreach ($name as $value) {
            if (isset($group[$value])) {
                $arr[$value] = $group[$value];
            }
        }

        return $arr;
    }

    /**
     * 获得还未配置支付的商户号
     * @return mixed
     */
    public static function getMerchantConfig() {
        $users = UserModel::column('nickname', 'merchant_id');
        // 获取已经设置好的商户号配置
        $all_mconfig = self::column('id');
        // 获取所有用户的商户号
        $keys = array_keys($users);
        // 计算数组的差集
        $diff = array_diff($keys, $all_mconfig);
        $arr = [];
        foreach ($diff as $value) {
            $arr[$value] = $users[$value];
        }
        return $arr;
    }

}
